package com.CGFrame.struts.bean.unit;

import java.util.Iterator;
import java.util.LinkedHashSet;

import com.CGFrame.struts.POJOs.Element;
import com.CGFrame.struts.POJOs.Elementgroup;
import com.CGFrame.struts.POJOs.Shot;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;

public class ElementGroupBean {
	private Elementgroup elementGroup; 
	public ElementGroupBean(String id)
	{
		ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
		Elementgroup elementgroup =(Elementgroup)pop.UniqueQuery("Elementgroup", "elementGroupId,"+id);
		this.elementGroup = elementgroup;
	}
	
	public ElementGroupBean(Elementgroup elementgroup)
	{
		this.elementGroup = elementgroup;
	}
	
	public LinkedHashSet getAllElements()
	{
		LinkedHashSet lin_AllElements = new LinkedHashSet();
		lin_AllElements = this.getAllElements(this.elementGroup);
		return lin_AllElements;
	}
	private LinkedHashSet getAllElements(Elementgroup m_ElementGroup)
	{
		LinkedHashSet lin_AllElements = new LinkedHashSet();
	//	if (m_ElementGroup==null) return null;
		Iterator ite_SubElementGroups = m_ElementGroup.getElementgroups().iterator();
		while(ite_SubElementGroups.hasNext())
		{
			lin_AllElements.addAll(getAllElements( (Elementgroup)ite_SubElementGroups.next() ) );
			
		}
		lin_AllElements.addAll( m_ElementGroup.getElements() );
		return lin_AllElements;
	}
	public String getAllElementsId(){
		LinkedHashSet lhs=getAllElements();
		StringBuffer sb=new StringBuffer();
		for(Iterator iter=lhs.iterator();iter.hasNext();){
			Element ele=(Element)iter.next();
			sb.append(ele.getElementId()).append(",");
		}
		return sb.toString();
	}
}